package com.htfyun.eink.pw.draw.pen;

import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;

import androidx.annotation.NonNull;

import com.htfyun.eink.pw.configs.ConfigPen;
import com.htfyun.eink.pw.draw.IPWDrawPath;
import com.htfyun.eink.pw.draw.pointer.PWPointer;
import com.htfyun.eink.pw.draw.pointer.PWPointerActionEnums;

public abstract class PenShapeBase implements IPenShape {

    protected final Path floatPath = new Path();
    protected final Paint floatPaint = new Paint();

    public abstract PenDrawPointerResultEnums pointerDown(@NonNull IPWDrawPath draw, @NonNull PWPointer pointer);

    public abstract PenDrawPointerResultEnums pointerMove(@NonNull IPWDrawPath draw, @NonNull PWPointer pointer);

    public abstract PenDrawPointerResultEnums pointerUp(@NonNull IPWDrawPath draw, @NonNull PWPointer pointer);

    @NonNull
    @Override
    public PenDrawPointerResultEnums drawPointer(@NonNull IPWDrawPath draw, @NonNull PWPointer pointer) {
        return handlePointer(draw, pointer);
    }

    @NonNull
    @Override
    public Path getFloatPath() {
        return floatPath;
    }

    @NonNull
    @Override
    public Paint getFloatPaint() {
        return floatPaint;
    }

    public PenDrawPointerResultEnums handlePointer(@NonNull IPWDrawPath draw, @NonNull PWPointer pointer) {
        PWPointerActionEnums actionEnums = pointer.toPWPointerActionEnums();
        switch (actionEnums) {
            case DOWN:
                draw.getPaintConfig().configPaint(floatPaint);
                floatPaint.setAntiAlias(true);
                floatPaint.setStrokeWidth(ConfigPen.WRITER_STROKE_WIDTH_DEFAULT);
//                float strokeWidth = floatPaint.getStrokeWidth();
//                DashPathEffect dashPathEffect = new DashPathEffect(new float[]{strokeWidth * 8, strokeWidth}, 0);
                DashPathEffect dashPathEffect = new DashPathEffect(new float[]{10.0f, 10.0f}, 0);
                floatPaint.setPathEffect(dashPathEffect);
                return pointerDown(draw, pointer);
            case MOVE:
                return pointerMove(draw, pointer);
            case UP:
                return pointerUp(draw, pointer);
            default:
                break;
        }
        return PenDrawPointerResultEnums.NONE;
    }

}
